home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-03-30 | 23.4 KB | 1,066 lines | [TEXT/PJMM] |
- program AACK;
-
-
- uses
- AppleTalk, Globals, LowLevelATProcs, Hooks;
-
-
- procedure Crash;
- {This proc is called if we crash}
- begin
- ExitToShell;
- end;
-
-
- procedure SetUpToolbox;
- {This proc inits the Mac toolbox}
- begin
- MaxApplZone;
- MoreMasters;
- MoreMasters;
- MoreMasters;
- MoreMasters;
- InitGraf(@thePort);
- InitFonts;
- InitWindows;
- FlushEvents(everyEvent, 0);
- InitMenus;
- TEInit;
- InitDialogs(@Crash);
- InitCursor;
- end;
-
-
- procedure SetUpGlobals;
- {This proc does any app global inits}
- begin
- DoneFlag := F;
-
- DragRect := screenBits.bounds;
- with DragRect do
- begin
- top := top + 20; {NOTE! we really should use the mbarheight}
- left := left + 4;
- bottom := bottom - 4;
- right := right - 4;
- end;
-
- {Assume the new calls dont exist}
- NewCallsExist := F;
-
- SleepTime := 10;
-
- {$IFC TALK_DEBUG }
- with DebugOnRect do
- begin
- top := 0;
- left := 0;
- bottom := 4;
- right := 4;
- end;
-
- with SelfSendOnRect do
- begin
- top := 5;
- left := 0;
- bottom := 9;
- right := 4;
- end;
-
- {$ENDC}
-
- {Allow setup of any globals from the Hooks unit}
- SetUpHooksGlobals;
- end;
-
-
- procedure SetUpMenus;
- {This proc sets upthe generic codes menus}
- begin
- AppleMenu := GetMenu(APPLEMENUID);
- AddResMenu(AppleMenu, 'DRVR');
- InsertMenu(AppleMenu, 0);
-
- FileMenu := GetMenu(FILEMENUID);
- InsertMenu(FileMenu, 0);
-
- EditMenu := GetMenu(EDITMENUID);
- InsertMenu(EditMenu, 0);
-
- SpecialMenu := GetMenu(SPECIALMENUID);
- InsertMenu(SpecialMenu, 0);
-
- {Allow setup of any menus from the Hooks unit}
- SetUpHooksMenus;
-
- DrawMenuBar;
- end;
-
-
- procedure CloseWindows;
- {This proc closes the apps windows}
- begin
- {Allow closing of any windows from the Hooks unit}
- CloseHooksWindows;
-
- if UserWindowProcsChanged then
- HooksCloseUserWindowProc {Let the hook code do it magic}
- else
- begin
- LDispose(NameListHdl);
- CloseWindow(UserWindow);
- end;
- end;
-
-
- function GotWindows: Boolean;
- {This code sets up the apps windows, it returns T}
- {if it succeeds}
- var
- theCell: Cell;
- dBounds: Rect;
- begin
- {Assume we fail}
- GotWindows := F;
-
- UserWindowRect := DragRect;
- with UserWindowRect do
- begin
- top := top + 20;
- left := left + 4;
- bottom := top + 200;
- right := left + 225;
- end;
-
- {Get the UserWindow}
- UserWindow := NewWindow(@UserWRec, UserWindowRect, UserNTT.objStr, F, noGrowDocProc, WindowPtr(-1), T, 0);
- if UserWIndow <> nil then
- begin
- SetPort(UserWindow);
- ClipRect(UserWindow^.portRect);
- TextFont(monaco);
- TextSize(9);
-
- GetFontInfo(UserWindowFontInfo);
- with UserWindowFontInfo do
- TextHeight := ascent + descent + leading;
-
- {Set the # of rows to display in our list}
- MaxRows := 10;
-
- {Set the current list length to 0}
- NameListLength := 0;
-
- with dBounds do
- begin
- top := 0;
- left := 0;
- bottom := NameListLength; {no rows for now}
- right := 1; {one column}
- end;
-
- theCell.h := 0;
- theCell.v := 0;
-
- {Set up the lists view rect}
- with ListViewRect do
- begin
- top := 10;
- left := 10;
- bottom := (TextHeight * MaxRows) + ListViewRect.top;
- right := (32 * CharWidth('w')) + 8;
- end;
-
- {Try to get a ListHandle}
- NameListHdl := LNew(ListViewRect, dBounds, theCell, 0, UserWindow, T, F, F, T);
-
- if NameListHdl = nil then
- {We failed to get a ListHandle so close the UserWindow and exit}
- CloseWindow(UserWindow)
- else
- begin
- {We got the ListHandle, allow only one selection at a time from it}
- NameListHdl^^.selFlags := LOnlyOne;
-
- {Set up a rect to put a frame around our list}
- ListFrameRect := ListViewRect;
- with ListFrameRect do
- begin
- top := top - 1;
- left := left - 1;
- bottom := bottom + 1;
- right := right + 16;
-
- {Set up the pos to draw the LookUpName results at}
- with LookUpStringPos do
- begin
- h := left;
- v := bottom + TextHeight;
- end;
-
- {Set up the pos to draw the ConfirmName results at}
- with ConfirmStringPos do
- begin
- h := left;
- v := LookUpStringPos.v + TextHeight;
- end;
-
- end;
-
- {Set up the rect to erase the old LookUpName result}
- with LookUpStringRect do
- begin
- top := ListFrameRect.bottom + 1;
- left := UserWindow^.portRect.left;
- bottom := LookUpStringPos.v + UserWindowFontInfo.descent;
- right := UserWindow^.portRect.right;
- end;
-
- {Set up the rect to erase the old ConfirmName result}
- with ConfirmStringRect do
- begin
- top := LookUpStringRect.bottom + 1;
- left := UserWindow^.portRect.left;
- bottom := ConfirmStringPos.v + UserWindowFontInfo.descent;
- right := UserWindow^.portRect.right;
- end;
-
- {Set to false, assume no hook code override}
- UserWindowProcsChanged := F;
-
- {Allow setup of any windows from the Hooks unit}
- if SetUpHooksWindows = T then
- begin
- ShowWindow(UserWindow);
- {We succeeded! Return T}
- GotWindows := T;
- end
- else
- begin
- {SetUpHooksWindows failed}
- LDispose(NameListHdl);
- CloseWindow(UserWindow);
- end;
- end;
- end;
- end;
-
-
- procedure DoDrag;
- {This code drags windows around}
- begin
- DragWindow(WhichWindow, Evt.where, DragRect);
- end;
-
-
- procedure ActivateUserWindow;
- {This code activates the apps windows}
- begin
- if UserWindowProcsChanged then
- HooksActivateUserWindowProc {Let the hook code do its magic}
- else
- LActivate(T, NameListHdl);
- end;
-
-
- procedure DeactivateUserWindow;
- {This code deactivates the apps windows}
- begin
- if UserWindowProcsChanged then
- HooksDeactivateUserWindowProc {Let the hook code do its magic}
- else
- LActivate(F, NameListHdl);
- end;
-
-
- procedure UpdateNameList;
- {This code updates the list of names in the NameListHandle}
- var
- theAddress: AddrBlock;
- theCell: Cell;
- theNTT: EntityName;
- theNum: Integer;
- err: OSErr;
- thePtr: Ptr;
- begin
- with LookUpNamePb do
- begin
- if NameListLength <> 0 then
- LDelRow(NameListLength, 0, NameListHdl); {Delete any rows present}
- NameListLength := xMPPPb.numGotten; {Get the new # of rows needed}
- if NameListLength <> 0 then
- begin
- theNum := LAddRow(NameListLength, 0, NameListHdl); {Add the # of new rows}
- theCell.h := 0;
- for theNum := 1 to NameListLength do
- begin
- err := NBPExtract(@LookUpBuffer, NameListLength, theNum, theNTT, theAddress); {extract a name}
- if err = noErr then
- begin
- theCell.v := theNum - 1; {Cells are numbered starting from zero so bump row # back}
- thePtr := Ptr(ORD4(@theNTT.objStr) + 1); {Pt to the data}
- LSetCell(thePtr, length(theNTT.objStr), theCell, NameListHdl); {Set the cells data}
- end;
- end;
- {Select the first row}
- theCell.h := 0;
- theCell.v := 0;
- LSetSelect(T, theCell, NameListHdl);
- end;
- end;
- end;
-
-
- procedure UpdateUserWindow;
- {This code updates the UserWindow}
- var
- theRgn: RgnHandle;
- begin
- if UserWindowProcsChanged then
- HooksUpdateUserWindowProc {Let the hook code do its magic}
- else
- begin
- {$IFC TALK_DEBUG }
- ForeColor(redColor);
- FillRect(DebugOnRect, black);
-
- if SelfSendOn then
- begin
- ForeColor(cyanColor);
- FillRect(SelfSendOnRect, black);
- end
- else
- begin
- ForeColor(cyanColor);
- FrameRect(SelfSendOnRect);
- end;
-
- ForeColor(blackColor);
- {$ENDC}
-
- FrameRect(ListFrameRect); {Put a frame around the list}
- theRgn := UserWindow^.visRgn;
- LUpdate(theRgn, NameListHdl); {Update the list}
- DrawLookUpString; {Draw in last LookUpName result}
- DrawConfirmString; {Draw in last ConfirmName result}
- end;
- end;
-
-
- procedure DoActivate;
- {This code activates any app windows}
- var
- theWindow: WindowPtr;
- begin
- theWindow := WindowPtr(Evt.message);
- SetPort(theWindow);
- if BAnd(activeFlag, Evt.modifiers) <> 0 then
- begin
- if theWindow = UserWindow then
- ActivateUserWindow
- else
- ActivateHooksWindow(theWindow); {Let the hook code activate its windows}
- end
- else
- begin
- if theWindow = UserWindow then
- DeactivateUserWindow
- else
- DeactivateHooksWindow(theWindow); {Let the hook code deactivate its windows}
- end;
- end;
-
-
- procedure DoUpdate;
- {This proc does updates of app windows}
- var
- oldPort: GrafPtr;
- theWindow: WindowPtr;
- begin
- GetPort(oldPort);
-
- theWindow := WindowPtr(Evt.message);
- SetPort(theWindow);
-
- BeginUpdate(theWindow);
-
- if theWindow = UserWindow then
- UpdateUserWindow
- else
- UpdateHooksWindow(theWindow); {Let the hook code update any of its windows}
-
- EndUpdate(theWindow);
-
- SetPort(oldPort);
- end;
-
-
- procedure DoMFEvent;
- {This code handles MultiFinder events such as deac/activation of}
- {windows upon suspend/resume events}
- var
- theWindow: WindowPtr;
- begin
- theWindow := FrontWindow;
- case BSR(Evt.message, 24) of {high byte of message}
- SUSPENDRESUMEMSG:
- begin
- if BAnd(Evt.message, RESUMEMASK) <> 0 then
- begin
- SleepTime := 10;
- SetPort(theWindow);
- if theWindow = UserWindow then
- ActivateUserWindow
- else
- ActivateHooksWindow(theWindow); {Let the hook code activate its windows}
- end
- else
- begin
- SleepTime := 60;
- SetPort(theWindow);
- if theWindow = UserWindow then
- DeactivateUserWindow
- else
- DeactivateHooksWindow(theWindow); {Let the hook code deactivate its windows}
- end;
- end;
- otherwise
- end;
- end;
-
-
- function UserRegistered: Boolean;
- {This proc lets the User register on the network, it return T}
- {T if it succeeds}
- label
- 100;
- var
- localATPPb: ATPParamBlock;
- theDialog: DialogPtr;
- theDRec: DialogRecord;
- oldPort: GrafPtr;
- item: Handle;
- itemHit: Integer;
- localMPPPb: MPPParamBlock;
- err: OSErr;
- itemRect: Rect;
- theStr32Hdl: Str32Hdl;
- theString: Str255;
- begin
- {Assume we fail}
- UserRegistered := F;
-
- {Get the string entered in the 'Chooser'}
- theStr32Hdl := Str32Hdl(GetResource('STR ', rCHOOSERUSERSTRID));
-
- {If there is no default user name from the chooser, then set theString to the}
- {null string}
- if theStr32Hdl = nil then
- theString := '';
-
- GetPort(oldPort);
-
- theDialog := GetNewDialog(rUSERNAMEDLOGID, @theDRec, WindowPtr(-1));
- SetPort(theDialog);
-
- ShowWindow(theDialog);
-
- 100:
- if theStr32Hdl <> nil then
- begin
- HLock(Handle(theStr32Hdl));
- theString := theStr32Hdl^^; {theString = the chooser string}
- HUnlock(Handle(theStr32Hdl));
- end;
-
- {Show theString in the dialog and select it}
- GetDItem(theDialog, rUSERNAMEITEM, itemHit, item, itemRect);
- SetIText(item, theString);
- SelIText(theDialog, rUSERNAMEITEM, 0, 32767);
-
- {Loop until OK or Cancel is hit}
- repeat
- ModalDialog(nil, itemHit)
- until ((itemHit = ok) or (itemHit = cancel));
-
- if itemHit = ok then
- begin
- GetDItem(theDialog, rUSERNAMEITEM, itemHit, item, itemRect);
- GetIText(item, theString);
- itemHit := length(theString);
- if (itemHit > 0) and (itemHit <= MAXNAMELENGTH) then
- begin
- {theString must be > 0 but < 32}
- {First try to open a socket}
- with localATPPb do
- begin
- ioCompletion := nil;
- atpSocket := 0;
- with addrBlock do
- begin
- aNet := 0;
- aNode := 0;
- aSocket := 0;
- end;
- end;
-
- err := POpenATPSkt(@localATPPb, SYNC);
- if err = noErr then
- begin
- UserSkt := localATPPb.atpSocket; {Save the socket #}
- {Try to register the user on the network}
- NBPSetEntity(@UserNTT, theString, USERTYPE, ANYZONE);
- NBPSetNTE(@NBPsNTE, UserNTT.objStr, USERTYPE, ANYZONE, UserSkt); {Set up the nte that NBP wants}
-
- with localMPPPb do
- begin
- ioCompletion := nil;
- interval := 3;
- count := 3;
- entityPtr := @NBPsNTE;
- verifyFlag := DOVERIFY; {Make sure we register with a unique name}
- end;
-
- err := PRegisterName(@localMPPPb, SYNC);
- if err = noErr then
- begin
- {We registered successfully!}
- UserRegistered := HooksRegistered; {Let the hook code do its magic}
-
- {$IFC TALK_DEBUG }
- {Enable self sending if the new calls exist}
- if NewCallsExist then
- begin
- localMPPPb.newSelfFlag := SENDSELF;
- err := PSetSelfSend(@localMPPPb, SYNC);
- if err = noErr then
- begin
- OldSelfFlag := localMPPPb.oldSelfFlag; {Save the old self flag state}
- SelfSendOn := T; {Mark our selfsend flag as on}
- end
- else
- SelfSendOn := F; {We failed, mark our selfsend flag as off}
- end
- else
- SelfSendOn := F; {Mark our selfsend flag as off}
- {$ENDC}
- end
- else
- begin
- {PRegisterName failed}
- {Close the UserSkt}
- localATPPb.atpSocket := UserSkt;
- err := PCloseATPSkt(@localATPPb, SYNC);
- end;
- end;
- end
- else
- {User didn't enter a valid string}
- goto 100;
- end;
-
- {Close the dialog and return the result}
- CloseDialog(theDialog);
- SetPort(oldPort);
- end;
-
-
- function AppleTalkOK: Boolean;
- {This proc makes sure we're running on at least a 512KE}
- {, it returns T if so and checks to see if the new calls exist}
- var
- err: OSErr;
- theWorld: SysEnvRec;
- begin
- {Assume we failed}
- AppleTalkOK := F;
-
- err := MPPOpen; {Open AppleTalk}
- if err = noErr then
- begin
- err := SysEnvirons(1, theWorld);
- if err = noErr then
- begin
- with theWorld do
- begin
- if machineType >= env512KE then
- begin
- {We've got at least a 512KE}
- if atDrvrVersNum >= XNCVERSION then
- {We've got the new calls}
- NewCallsExist := T;
- AppleTalkOK := UserRegistered; {Let the user try to register}
- end;
- end;
- end;
- end;
- end;
-
-
- procedure AppleTalkCallChecks;
- {This proc checks to see if any of ASYNC calls have finished}
- var
- oldPort: GrafPtr;
- begin
- with LookUpNamePb do
- begin
- if CallDone <> 0 then
- begin
- PbInUse := F;
- CallDone := 0;
- GetPort(oldPort);
- SetPort(UserWindow);
- UpdateNameList;
- LookUpString := 'done';
- DrawLookUpString;
- SetPort(oldPort);
- end;
- end;
-
- {Allow any AppleTalk call checks in the Hooks unit}
- HooksAppleTalkCallChecks;
- end;
-
-
- procedure CloseUpAppleTalk;
- {This proc closes up the apps AppleTalk socket and lets the hook}
- {code cleanup anything it did with AppleTalk}
- var
- localATPPb: ATPParamBlock;
- localMPPPb: MPPParamBlock;
- err: OSErr;
- begin
- {A LookUp call may not have finished, if the new calls exist}
- {then KillNBP it, if not then we must wait till it finishes.}
- with LookUpNamePb do
- begin
- if PbInUse then
- begin
- {There is a LookUpName in progress}
- if NewCallsExist then
- begin
- {We've got the new calls so we can kill it}
- with localMPPPb do
- begin
- ioCompletion := nil;
- nKillQEl := @LookUpNamePb.xMPPPb;
- end;
- err := PKillNBP(@localMPPPb, SYNC);
- if err <> noErr then
- begin
- {We failed to KillNBP the LookUp so we'll just loop till the LookUp is done}
- {NOTE that we test the CallDone field since its changed by the completion routine, NOT}
- {the PbInUse field}
- while LookUpNamePb.CallDone = 0 do
- ;
- end;
- end
- else
- {The new calls dont exist so we'll just loop till the LookUp is done}
- {NOTE that we test the CallDone field since its changed by the completion routine, NOT}
- {the PbInUse field}
- while LookUpNamePb.CallDone = 0 do
- ;
- end;
- end;
-
-
- {Allow the Hooks unit to closeup any AppleTalk calls it made}
- HooksCloseUpAppleTalk;
-
- {Close the UserSkt}
- localATPPb.atpSocket := UserSkt;
- err := PCloseATPSkt(@localATPPb, SYNC);
- if err <> noErr then
- SysBeep(1);
-
- {Remove the users name from the network}
- localMPPPb.entityPtr := @UserNTT;
- err := PRemoveName(@localMPPPb, SYNC);
- if err <> noErr then
- SysBeep(1);
-
- {$IFC TALK_DEBUG }
- {Restore the SelfSendFlag to its former state}
- if NewCallsExist then
- begin
- if SelfSendOn then
- begin
- if OldSelfFlag = 0 then
- begin
- {Turn it off if it wasn't on before}
- localMPPPb.newSelfFlag := OldSelfFlag;
- err := PSetSelfSend(@localMPPPb, SYNC);
- end;
- end;
- end;
- {$ENDC}
- end;
-
-
- function AppleTalkGlobalsSetUp: Boolean;
- {This proc inits any app AppleTalk globals}
- begin
- {Assume error}
- AppleTalkGlobalsSetUp := F;
-
- with LookUpNamePb do
- begin
- PbInUse := F;
- CallDone := 0;
- end;
-
- ConfirmString := 'never done';
- LookUpString := 'never done';
-
- {Allow setup of AppleTalk globals from the Hooks unit}
- if HooksAppleTalkGlobalsSetUp then
- AppleTalkGlobalsSetUp := T;
- end;
-
-
- procedure DoWNEs;
- {Do a few WNEs to make sure our dialog comes up in front}
- var
- theResult: Boolean;
- begin
- theResult := WaitNextEvent(everyEvent, Evt, 0, nil);
- theResult := WaitNextEvent(everyEvent, Evt, 0, nil);
- theResult := WaitNextEvent(everyEvent, Evt, 0, nil);
- theResult := WaitNextEvent(everyEvent, Evt, 0, nil);
- theResult := WaitNextEvent(everyEvent, Evt, 0, nil);
- end;
-
-
- procedure DoAbout;
- {This proc shows our About box}
- var
- theDialog: DialogPtr;
- theDRec: DialogRecord;
- oldPort: GrafPtr;
- itemhit: Integer;
- begin
- GetPort(oldPort);
-
- theDialog := GetNewDialog(rABOUTDLOGID, @theDRec, WindowPtr(-1));
- SetPort(theDialog);
- ShowWindow(theDialog);
-
- repeat
- ModalDialog(nil, itemHit)
- until (itemHit = ok);
-
- CloseDialog(theDialog);
-
- SetPort(oldPort);
- end;
-
-
- procedure DoAppleMenu (item: Integer);
- {This proc handles the Apple Menu}
- begin
- case item of
- ABOUTITEM:
- DoAbout;
- otherwise
- end;
- end;
-
-
- procedure DoFileMenu (item: Integer);
- {This proc handles the File Menu}
- begin
- case item of
- QUITITEM:
- DoneFlag := T;
- otherwise
- end;
- end;
-
-
- procedure DoLookUp;
- {This proc does an ASYNC LookUpName}
- var
- oldPort: GrafPtr;
- err: OSErr;
- begin
- with LookUpNamePb do
- begin
- if PbInUse = F then
- begin
- {If we're not already doing one}
- NBPSetEntity(@LookUpNTT, ANYOJB, USERTYPE, ANYZONE); {Setup who to look for}
-
- CallDone := 0;
-
- with xMPPPb do
- begin
- ioCompletion := @XCompletionRoutine;
- {$IFC TALK_DEBUG }
- interval := 2;
- count := 3;
- {$ELSC}
- interval := 6;
- count := 5;
- {$ENDC}
- entityPtr := @LookUpNTT;
- retBuffPtr := @LookUpBuffer;
- retBuffSize := sizeof(LookUpBuffer);
- maxToGet := MAXTOLOOKUP;
- end;
-
- err := PLookUpName(@xMPPPb, ASYNC);
- {Show the LookUps progress}
- GetPort(oldPort);
- SetPort(UserWindow);
- if err = noErr then
- begin
- PbInUse := T;
- LookUpString := 'in progress';
- end
- else
- LookUpString := 'error';
- DrawLookUpString;
- SetPort(oldPort);
- end;
- end;
- end;
-
-
- procedure DoConfirm;
- {This proc does a SYNC ConfirmName}
- var
- theAddress: AddrBlock;
- nameIsSelected: Boolean;
- theCell: Cell;
- extractedNTT, ntt2Confirm: EntityName;
- oldPort: GrafPtr;
- err: OSErr;
- begin
- if LookUpNamePb.PbInUse then
- begin
- {Dont try to ConfirmName while a LookUp is in progress}
- GetPort(oldPort);
- SetPort(UserWindow);
- ConfirmString := 'LookUp in progress';
- DrawConfirmString;
- SetPort(oldPort);
- end
- else
- begin
- theCell.h := 0;
- theCell.v := 0;
- nameIsSelected := LGetSelect(T, theCell, NameListHdl); {Get the selected list item}
-
- if nameIsSelected then
- begin
- {Only do a Confirm if an item in the list is selected}
- theCell.v := theCell.v + 1;
- err := NBPExtract(@LookUpBuffer, NameListLength, theCell.v, extractedNTT, theAddress); {Get the address}
- if err = noErr then
- begin
- NBPSetEntity(@ntt2Confirm, extractedNTT.objStr, extractedNTT.typeStr, extractedNTT.zoneStr);
-
- err := NTTExists(ntt2Confirm, theAddress); {Check if the NTT exists}
- {Show the result of the ConfirmName}
- GetPort(oldPort);
- SetPort(UserWindow);
- if err = noErr then
- ConfirmString := 'confirmed'
- else
- begin
- case err of
- nbpNoConfirm:
- ConfirmString := 'can''t confirm ';
- nbpConfDiff:
- ConfirmString := 'moved';
- otherwise
- ConfirmString := 'error';
- end;
- end;
- DrawConfirmString;
- SetPort(oldPort);
- end;
- end;
- end;
- end;
-
-
- procedure DoSendRequest;
- {This is the generic codes response to choosing 'Send'}
- begin
- SysBeep(1);
- end;
-
-
- procedure DoSpecialMenu (item: Integer);
- {This proc handles the Special Menu}
- begin
- case item of
- LOOKUPITEM:
- DoLookUp;
- CONFIRMITEM:
- DoConfirm;
- SENDITEM:
- DoSendRequest;
- otherwise
- end;
- end;
-
-
- procedure DoMenu (menuChoice: LongInt);
- {This proc handles menu selections}
- var
- theItem, theMenu: Integer;
- begin
- theItem := LoWord(menuChoice);
- theMenu := HiWord(menuChoice);
-
- if HookedMenuChoice(theMenu, theItem) = F then
- begin
- {Hook code didn't handle the menu choice so the generic code must}
- case theMenu of
- APPLEMENUID:
- DoAppleMenu(theItem);
- FILEMENUID:
- DoFileMenu(theItem);
- SPECIALMENUID:
- DoSpecialMenu(theItem);
- otherwise
- end;
- end;
-
- HiliteMenu(0);
- end;
-
-
- procedure DoKDown;
- {This code handles keydowns}
- type
- Trick = packed record
- case Boolean of
- TRUE: (
- long: Longint
- );
- FALSE: (
- chr3, chr2, chr1, chr0: Char
- )
- end;
- var
- charCode: Char;
- trickVar: Trick;
- begin
- trickVar.long := Evt.message;
- charCode := trickVar.chr0;
- {IF BitAnd(Evt.modifiers, CmdKey) = CmdKey THEN}
- if BAnd(CmdKey, Evt.modifiers) <> 0 then
- DoMenu(MenuKey(charCode));
- end;
-
-
- procedure DoContentHit;
- {This code handles hits in the apps windows}
- var
- clickResult: Boolean;
- localPt: Point;
- begin
- if WhichWindow <> FrontWindow then
- SelectWindow(WhichWindow)
- else
- begin
- localPt := Evt.where;
- SetPort(WhichWindow);
- if WhichWindow = UserWindow then
- begin
- if UserWindowProcsChanged then
- HooksUserWindowDoContentHit {Let the hook code do its magic}
- else
- begin
- GlobalToLocal(localPt);
- if PtinRect(localPt, ListFrameRect) then
- clickResult := LClick(localPt, Evt.modifiers, NameListHdl);
- end;
- end
- else
- {A hook window was hit, let it handle it}
- DoHooksWindowContentHit;
- end;
- end;
-
-
- procedure DoMDown;
- {This code handles mouse down events}
- var
- theResult: Integer;
- begin
- theResult := FindWindow(Evt.where, WhichWindow);
- case theResult of
- inDrag:
- DoDrag;
- inMenuBar:
- DoMenu(MenuSelect(Evt.where));
- inContent:
- DoContentHit;
- otherwise
- end;
- end;
-
-
- procedure MainLoop;
- {This is the apps event loop}
- var
- theResult: Boolean;
- begin
- while DoneFlag = F do
- begin
- theResult := WaitNextEvent(everyEvent, Evt, SleepTime, nil);
- AppleTalkCallChecks; {Check to see if any ASYNC calls completed}
- if theResult then
- begin
- {Handle any event}
- case Evt.what of
- keyDown:
- DoKDown;
- mouseDown:
- DoMDown;
- activateEvt:
- DoActivate;
- updateEvt:
- DoUpdate;
- MFEVENT:
- DoMFEvent;
- otherwise
- end;
- end;
- end;
- end;
-
-
- {$I-}
- {We do our own inits}
- begin
- SetUpToolbox;
- SetUpGlobals;
- DoWNEs;
-
- if AppleTalkOK then
- begin
- SetUpMenus;
-
- if GotWindows then
- begin
-
- if AppleTalkGlobalsSetUp then
- begin
-
- MainLoop;
-
- CloseWindows;
- end;
- end;
-
- CloseUpAppleTalk;
- end;
-
- ExitToShell;
- end.